;(function($){
    $.fn.Gpagination = function (options) {
        var defaults = {
            //默认参数
            style: "default",   //样式种类， default普通顺序页码，list 横条式 页码
            totalCount:0,       //总共多少篇文章,必须重写
            totalNum: 0,    //总共多少页，必须重写
            viewNum:5,      //显示页码多少页
            currentNum:1,   //当前页码，默认第1页
            otherCls:"" ,    //未选中页码class，默认为空
            currentCls: "", //当前页选中class，默认为空
            url:"javascript:void(0)" ,         //页码链接生成结构 示例机构 "/news/{0}"
            clickevent:""                       //OnClick点击事件
        };

        var createHtml = function (options) {
            var totalNum = parseInt(options.totalNum);
            var viewNum = parseInt(options.viewNum);
            var currentNum = parseInt(options.currentNum);
            var totalCount = parseInt(options.totalCount);
            if (isNaN(totalNum) || isNaN(viewNum) || isNaN(currentNum)) {   //页码参数传递是否未数字
                console.error("页码传参不正确");
                return "";
            } else {
                var list = [];
                var start = currentNum - Math.ceil(viewNum/2) + 1;
                var end = currentNum + Math.floor(viewNum/2) + 1;
                for(var i = start;i < end; i++) {
                    if (i < 1 ) {
                        end = end + 1;
                    } else if (i > totalNum) {
                        if (list[0] > 1) {
                            list.splice(0,0,list[0]-1);
                        }
                    } else {
                        list.push(i);
                    }
                }
            }
            var html = "<div>\n" +
                            "<span>共<font>" + totalCount + "</font>篇文章 </span>\n";
            if (list[0] > 1) {
                html = html + "<a class=\" + options.otherCls + \" href=\"" + options.url.replace("{0}",currentNum-1) + "\" data-pagenum='"+ (currentNum-1) +"'>&lt</a>\n";
            }
            if (list[0] > 2) {
                html = html + "<a class=\" + options.otherCls + \" href=\"" + options.url.replace("{0}",1) + "\" data-pagenum='1'>1</a>\n...\n";
            }
            for (var j in list) {
                if (list[j] == currentNum) {
                    html = html + "<span class=\"" + options.currentCls + "\" href=\"" + options.url.replace("{0}",list[j]) + "\">" + list[j] + "</span>\n";
                } else {
                    html = html + "<a class=\"" + options.otherCls + "\" href=\"" + options.url.replace("{0}",list[j]) + "\" data-pagenum='"+ (list[j]) +"'>" + list[j] + "</a>\n";
                }
            }
            if(totalNum > list[list.length-1]) {
                html = html + "...\n<a class=\"" + options.otherCls + "\" href=\"" + options.url.replace("{0}",totalNum) + "\" data-pagenum='"+ (totalNum) +"'>" + totalNum + "</a>\n"
            }
            if (currentNum < totalNum) {
                html = html + "<a class=\"" + options.otherCls + "\" href=\"" + options.url.replace("{0}",currentNum+1) + "\" data-pagenum='"+ (currentNum+1) +"'>&gt</a>\n</div>";
            }
            return html;
        };
        var options = $.extend(defaults, options);
        return this.each(function () {
            //功能实现
            $(this).empty().append(createHtml(options))
        });
    }
})(jQuery);